package ch10.shili;

public class S02_WorkThread extends Thread{

    @Override
    public void run() {
        Thread t = Thread.currentThread();
        System.out.println(t.getName()+"开始摘苹果");
        for(int i = 0; i < 5; i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName()+" 进度: 第" + (i+1)+"棵");
        }
        System.out.println(t.getName()+"已经完成采摘任务");
    }
}

class ThreadTest{
    public static void main(String[] args) {
        S02_WorkThread t1 = new S02_WorkThread();
        S02_WorkThread t2 = new S02_WorkThread();
        t1.setName("果农A");
        t2.setName("果农B");
        t1.start(); //启动线程
        t2.start();
        Thread t = Thread.currentThread();
        System.out.println("当前线程:" + t.getName());
    }
}
